/*
* EP-Tracing System : a tool to trace mountain hike.           .kNNx
* Copyright (C) 2009  Raffaello Brondi                         'KNNNk
*                                                             ,XNNNl
* This program is free software:                             ,XNN0'
* you can redistribute it and/or modify                     ,XNNx.
* it under the terms of the                                'XNNl
* GNU General Public License                              .KNN:                     ..
* as published by                                        .0NNo                    .ONNO.
* the Free Software Foundation,                          xNNN.  :dkd,            .KNNNN;
* either version 3 of the License, or                   :NNNK ;XNNNNNo          ,KNNNX:
* (at your option) any later version.                   xNNNNcXNNNNNNk         cNNNNx.
*                                                       ,XNNNNNNNNNNX'       .xNNNK;
*                                                        .lKNNNNNNNK'       :KNNNo
*                                                          ;kNNNNNKxl;'.'l0NNNk.
* This program is distributed in                          .'  .:xXNNNNNNNNNNNO,
* the hope that it will be useful,                       :NNXd'   ,oONNNNNNk,
* but WITHOUT ANY WARRANTY;                              xNNNNN0c.    .;;,.
* without even the implied warranty of                   kNNNNNNNXd'
* MERCHANTABILITY or                                     xNNNNNNNNNNOc.
* FITNESS FOR A PARTICULAR PURPOSE.                      xNNNNNNNNNNNNXd.
* See the GNU General Public License                     ONNNN0.,o0NNNNNNl
* for more details.                                      0NNNNd    kNNNNNX.
*                                                        KNNNNl   oNNNNNXc
*                                                       .XNNNN:  dNNNNNx.
* You should have received a copy                       .XNNNN; lNNNNO'
* of the GNU General Public License                     .XNNNN; 'dxo'
* along with this program.                              .XNNNN;
* If not, see <http://www.gnu.org/licenses/>.            0NNNN:
*                                                        kNNNNc
*                                                        oNNNNd
*                                                        ;NNNN0
* Contact: rbrondi@gmail.com                             .XNNNN;
*                                                         kNNNNd
*                                                         .coo:.
*/

package EP.UI.Compass;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author Raffaello Brondi
 */
public class Compass extends Canvas {

    /** First value in vector*/
    private static final int X = 0;
    /** Second value in vector*/
    private static final int Y = 1;

    private int[] center;
    private int compassWidth;
    private int compassHeight;

    /** Abort hike recording*/
    private Command back;

    public Compass(CommandListener listener) {
        this.center = new int[]{
                    this.getWidth() / 2,
                    this.getHeight() / 2
                };
        this.compassWidth = this.getWidth() / 10;
        this.compassHeight = this.getHeight() / 4;
        this.back = new Command("Back", Command.BACK, 1);
        this.addCommand(back);
        this.setCommandListener(listener);
    }

    public Command getBackCommand(){
        return this.back;
    }

    protected void paint(Graphics g) {
        // clean the backround
        g.setColor(0xaaaaaa);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(0X00dd00);

        g.fillTriangle(this.center[Compass.X] - this.compassWidth / 2,
                this.center[Compass.Y],
                this.center[Compass.X],
                this.center[Compass.Y] - this.compassHeight,
                this.center[Compass.X],
                this.center[Compass.Y]);

        g.setColor(0X00bb00);

        g.fillTriangle(this.center[Compass.X] + this.compassWidth / 2,
                this.center[Compass.Y],
                this.center[Compass.X],
                this.center[Compass.Y] - this.compassHeight,
                this.center[Compass.X],
                this.center[Compass.Y]);
        g.setColor(0Xdd0000);

        g.fillTriangle(this.center[Compass.X] + this.compassWidth / 2,
                this.center[Compass.Y],
                this.center[Compass.X],
                this.center[Compass.Y] + this.compassHeight,
                this.center[Compass.X],
                this.center[Compass.Y]);

        g.setColor(0Xbb0000);

        g.fillTriangle(this.center[Compass.X] - this.compassWidth / 2,
                this.center[Compass.Y],
                this.center[Compass.X],
                this.center[Compass.Y] + this.compassHeight,
                this.center[Compass.X],
                this.center[Compass.Y]);
    }
}
